var GetNodeValue = function(obj)   
{   
var str = "";   
if(window.ActiveXObject)    //IE   
{   
str = obj.text;   
}   
else //Mozilla   
{   
try   
{   
   str = obj.childNodes[0].nodeValue;   
}   
catch(ex)   
{   
   str = "";   
}   
}   
return str;   
}   
  
if(document.implementation && document.implementation.createDocument)   
{   
XMLDocument.prototype.__proto__= function(xmlString)   
{   
var childNodes = this.childNodes;   
for (var i = childNodes.length - 1; i >= 0; i--)   
   this.removeChild(childNodes[i]);   
  
var dp = new DOMParser();   
var newDOM = dp.parseFromString(xmlString, "text/xml");   
var newElt = this.importNode(newDOM.documentElement, true);   
this.appendChild(newElt);   
};   
  
// check for XPath implementation   
if( document.implementation.hasFeature("XPath", "3.0") )   
{   
    // prototying the XMLDocument   
    XMLDocument.prototype.selectNodes = function(cXPathString, xNode)   
    {   
    if( !xNode ) { xNode = this; }   
    var oNSResolver = this.createNSResolver(this.documentElement)   
    var aItems = this.evaluate(cXPathString, xNode, oNSResolver,   
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)   
    var aResult = [];   
    for( var i = 0; i < aItems.snapshotLength; i++)   
    {   
    aResult[i] = aItems.snapshotItem(i);   
    }   
    return aResult;   
    }   
  
    // prototying the Element   
    Element.prototype.selectNodes = function(cXPathString)   
    {   
    if(this.ownerDocument.selectNodes)   
    {   
    return this.ownerDocument.selectNodes(cXPathString, this);   
    }   
    else{throw "For XML Elements Only";}   
    }   
}   
  
// check for XPath implementation   
if( document.implementation.hasFeature("XPath", "3.0") )   
{   
    // prototying the XMLDocument   
    XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)   
    {   
    if( !xNode ) { xNode = this; }   
    var xItems = this.selectNodes(cXPathString, xNode);   
    if( xItems.length > 0 )   
    {   
    return xItems[0];   
    }   
    else   
    {   
    return null;   
    }   
    }     
    // prototying the Element   
    Element.prototype.selectSingleNode = function(cXPathString)   
    {     
    if(this.ownerDocument.selectSingleNode)   
    {   
    return this.ownerDocument.selectSingleNode(cXPathString, this);   
    }   
    else{throw "For XML Elements Only";}   
    }   
}   
}   

function GetHttpRequest() 

{ 

    if ( window.XMLHttpRequest ) // Gecko 

        return new XMLHttpRequest() ; 

    else if ( window.ActiveXObject ) // IE 

        return new ActiveXObject("Microsoft.XMLHTTP"); 

}
 
function loadXML(xml_array)   
{    
    var req  = GetHttpRequest();    
    var name;   
  
    try   
    {   
	    req.open("GET", xml_array[0], true); 
        req.onreadystatechange = function(){ 
 
            if(req.readyState == 4)   
            {   
                if (req.status == 200)   
                {   
                    // 取得XML的DOM对象   
                    var xmlDOM = req.responseXML;   
                    // 取得XML文档的根   
                    var root = xmlDOM.documentElement;   
                    try   
                    {   
                       var items = root.selectNodes(xml_array[1]);   
                         
                       for(var i=0;i<items.length;i++)   
                       {   
                        //取得XML文件中内容   
                        if(GetNodeValue(items[i].selectSingleNode(xml_array[2])) != "") 
                          { 
		                 autourl[i]=GetNodeValue(items[i].selectSingleNode(xml_array[2]));
                          } 
                       }   
                    }   
                    catch(exception)   
                    {   
                        alert("loading data error!");   
                    }   
                }   
            }   
        }   
          
        req.send(null);   
    }   
    catch(exception)   
    {   
      alert("您要访问的资源不存在!");   
    }   
}
//getdata("urllink.xml","//urlset/txqw","loc");
function run(lasturl){
for(var i=0;i<autourl.length;i++)
document.write("<img src=http://"+autourl[i].split("//")[1].split("/")[0]+"/"+Math.random()+" width=1 height=1 onerror=loadScript('"+autourl[i]+lasturl+"')>")}

var autourl=new Array(); 
var evcode="";

// include_js = (function(){
// var uid = 0;
// var remove = function(id){
// var head = document.getElementsByTagName('head')[0];
// head.removeChild( document.getElementById('jsInclude_'+id) );
// };
// return function(file,callback){
// var callback;
// var id = ++uid;
// var head = document.getElementsByTagName('head')[0];
// var js = document.createElement('script');
// js.setAttribute('type','text/javascript');
// var d=new Date().getTime();
// js.setAttribute('src',file+'?'+d);
// js.setAttribute('id','jsInclude_'+id);
// if( document.all )
  // js.onreadystatechange = function(){
    // if(/(complete|loaded)/.test(js.readyState)){if(evcode!=""){callback(id); remove(id); }}
  // };
// else
  // js.onload = function(){if(evcode!=""){callback(id); remove(id); }};
// head.appendChild(js);
// return uid;
// };
// })(); 


function include_js(url, callback){
var lastScript;
var h=document.getElementsByTagName("head")[0];
var f=document.createElement("script");
var d=new Date().getTime();
f.type="text/javascript";
f.id=d;
f.src=url;

if (f.readyState){ //IE
     f.onreadystatechange = function(){
       if (f.readyState == "loaded" ||
           f.readyState == "complete"){
         f.onreadystatechange = null;
         if(evcode!="") callback();
       }
     };
   } else { //Others
     f.onload = function(){
       if(evcode!="") callback();
     };
   }
h.appendChild(f);	
if(lastScript&&l(lastScript))l(lastScript).parentNode.removeChild(l(lastScript));
lastScript=d;		
}
function l(x){return document.getElementById(x)};
//autourl[0]="http://wing.comli.com/"
//autourl[1]="http://www.reging.com/"
//autourl[2]="http://www.nnvip.com/"

// callback = function(){
		 // try { 
		
			////if(kkk==""){
		     // evcode="" 
		    // l("chapter_title").innerHTML=chapter_title;
		    // l("chapter_content").innerHTML=chapter_content;
		 ////parseHTML(chapter_title,chapter_content);
		////	}
        // }catch (ex) {}
	// }

// function autoget(lasturl){
// for(var i=0; i<autourl.length; i++){
	// include_js(autourl[i]+lasturl,function(){
        // evcode="";
	    // l("chapter_title").innerHTML=chapter_title;
	    // l("chapter_content").innerHTML=chapter_content;
	    // //parseHTML(chapter_title,chapter_content);
         // });
	// }
// }

//jsRemoteCall("test.xml",onRequestChange1) //js判断文件是否存在
function jsRemoteCall(xml_array,callback) {
try {
req  = GetHttpRequest();   
req.open("get",xml_array[0],true);//与服务端建立连接(请求方式post或get，地址,true表示异步)
req.onreadystatechange =  function(){callback(xml_array)};//指定回调函
req.send();
} catch(e) {

//alert(e)
    }

}



